﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "GcmpControlFactory.h"
#include "IControl.h" 
#include "IComboBoxDefinition.h"
#include "QtComboBox.h"
#include "IProgressBarDefinition.h"
#include "QtProgressBar.h"
#include "ICheckBoxGroupDefinition.h"
#include "QtCheckBoxGroup.h"
#include "IRadioButtonGroupDefinition.h"
#include "QtRadioButtonGroup.h"
#include "ICommandButtonDefinition.h"
#include "QtButton.h"
#include "GbmpNew.h"
#include "TransferOwnership.h"
#include "QtLineEdit.h"
#include "QtLabel.h"
#include "ILineEditDefinition.h"
#include "ILabelDefinition.h"
#include "QtCommandButtonMenu.h"
#include "ICommandButtonMenuDefinition.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

// 数据定义创建工厂实现类

namespace gcmp
{
    GcmpControlFactory s_factory;
}

using namespace gcmp;

gcmp::GcmpControlFactory::GcmpControlFactory()
{
    Set(this);
}

gcmp::GcmpControlFactory::~GcmpControlFactory()
{
    Set(nullptr);
}

OwnerPtr<IControl> gcmp::GcmpControlFactory::CreateQtButton(OwnerPtr<ICommandButtonDefinition> opDefinition)
{
    return NEW_AS_OWNER_PTR(QtButton, TransferOwnership(opDefinition));
}

OwnerPtr<IControl> gcmp::GcmpControlFactory::CreateQtLineEdit(OwnerPtr<ILineEditDefinition> opDefinition)
{
    return NEW_AS_OWNER_PTR(QtLineEdit, TransferOwnership(opDefinition));
}

OwnerPtr<IControl> gcmp::GcmpControlFactory::CreateQtLabel(OwnerPtr<ILabelDefinition> opDefinition)
{
    return NEW_AS_OWNER_PTR(QtLabel, TransferOwnership(opDefinition));
}

OwnerPtr<IControl> gcmp::GcmpControlFactory::CreateQtCommandButtonMenu(OwnerPtr<ICommandButtonMenuDefinition> opDefinition)
{
    return NEW_AS_OWNER_PTR(QtCommandButtonMenu, TransferOwnership(opDefinition));
}

gcmp::OwnerPtr<gcmp::IControl> gcmp::GcmpControlFactory::CreateQtComboBox(OwnerPtr<IComboBoxDefinition> pControlDefinition)
{
    return NEW_AS_OWNER_PTR(QtComboBox, TransferOwnership(pControlDefinition));
}

gcmp::OwnerPtr<gcmp::IControl> gcmp::GcmpControlFactory::CreateQtProgressBar(OwnerPtr<IProgressBarDefinition> pControlDefinition)
{
    return NEW_AS_OWNER_PTR(QtProgressBar, TransferOwnership(pControlDefinition));
}

gcmp::OwnerPtr<gcmp::IControl> gcmp::GcmpControlFactory::CreateQtRadioButtonGroup(OwnerPtr<IRadioButtonGroupDefinition> pControlDefinition, UInt64 parentWinId)
{
    QWidget* pParent = QWidget::find((WId)(parentWinId));
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParent, L"pParent为空",L"GDMPLab",L"2024-03-30");
    return NEW_AS_OWNER_PTR(QtRadioButtonGroup, TransferOwnership(pControlDefinition), pParent);
}

gcmp::OwnerPtr<gcmp::IControl> gcmp::GcmpControlFactory::CreateQtCheckBoxGroup(OwnerPtr<ICheckBoxGroupDefinition> pControlDefinition, UInt64 parentWinId)
{
    QWidget* pParent = QWidget::find((WId)(parentWinId));
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pParent, L"pParent为空",L"GDMPLab",L"2024-03-30");
    return NEW_AS_OWNER_PTR(QtCheckBoxGroup, TransferOwnership(pControlDefinition), pParent);
}
